from codex import * from time import sleep from random import randrange import sys #initialize variables for choices of user and pictures/lights user = 0 picchoice = 0 def get_random_color(): red = randrange(256) green = randrange(256) blue = randrange(256) return (red, green, blue) #create lists for both pictures and lights user1_piclist = [pics.HEART, pics.HEART_SMALL, pics.MUSIC, pics.HAPPY, pics.SAD, pics.SURPRISED] user2_piclist = [pics.ASLEEP, pics.TARGET, pics.TSHIRT, pics.PLANE, pics.HOUSE, pics.TIARA] #define the last indexes for each list USER1_PIC_LAST_INDEX = len(user1_piclist) - 1 USER2_PIC_LAST_INDEX = len(user2_piclist) - 1 #opening pixels.set(0, get_random_color()) pixels.set(1, get_random_color()) pixels.set(2, get_random_color()) pixels.set(3, get_random_color()) sleep(0.1) display.draw_text('Welcome!', x = 80, scale=2, y=10, color=WHITE) display.draw_line(0, 240, 120, 80, RED) display.draw_line(240, 240, 120, 80, RED) display.draw_line(240, 239, 0, 239, RED) sleep(2) display.clear() display.draw_text('After you log in,', x = 0, scale=2, y=10, color=WHITE) display.draw_text('press left and right', x = 0, scale=2, y=40, color=WHITE) display.draw_text('to switch pictures.', x = 0, scale=2, y=70, color=WHITE) display.draw_text('Press up to', x = 0, scale=2, y=120, color=WHITE) display.draw_text('change lights.', x = 0, scale=2, y=150, color=WHITE) display.draw_text('Press down to exit.', x = 0, scale=2, y=210, color=WHITE) sleep(5) display.clear() display.draw_text('If you are User1,', x = 0, scale=2, y=10, color=WHITE) display.draw_text('press the A Button.', x = 0, scale=2, y=40, color=WHITE) display.draw_text('If you are User2,', x = 0, scale=2, y=90, color=WHITE) display.draw_text('press the B Button.', x = 0, scale=2, y=120, color=WHITE) display.draw_line(0, 240, 120, 150, RED) display.draw_line(240, 240, 120, 150, RED) display.draw_line(240, 239, 0, 239, RED) #switching users loop while True: pixels.set(0, get_random_color()) pixels.set(1, get_random_color()) pixels.set(2, get_random_color()) pixels.set(3, get_random_color()) sleep(0.2) if buttons.was_pressed(BTN_A): user = 1 leds.set(LED_A, True) if buttons.was_pressed(BTN_B): user = 2 leds.set(LED_B, True) #user1 loop while user == 1: #accessing the lists my_image = user1_piclist[picchoice] if type(my_image) == tuple: display.fill(my_image) else: display.show(my_image) #controls for switching pictures and lights if buttons.was_pressed(BTN_R): picchoice += 1 if picchoice > USER1_PIC_LAST_INDEX: picchoice = 0 if buttons.was_pressed(BTN_L): picchoice -= 1 if picchoice < 0: picchoice = USER1_PIC_LAST_INDEX #switching colors if buttons.was_pressed(BTN_U): pixels.set(0, get_random_color()) pixels.set(1, get_random_color()) pixels.set(2, get_random_color()) pixels.set(3, get_random_color()) #exiting the program if buttons.was_pressed(BTN_D): sys.exit() #switching to the other user if buttons.was_pressed(BTN_B): user = 2 leds.set(LED_B, True) leds.set(LED_A, False) #user2 loop while user == 2: #accessing the lists my_image = user2_piclist[picchoice] if type(my_image) == tuple: display.fill(my_image) else: display.show(my_image) #controls for switching pictures and lights if buttons.was_pressed(BTN_R): picchoice += 1 if picchoice > USER2_PIC_LAST_INDEX: picchoice = 0 if buttons.was_pressed(BTN_L): picchoice -= 1 if picchoice < 0: picchoice = USER2_PIC_LAST_INDEX #switching colors if buttons.was_pressed(BTN_U): pixels.set(0, get_random_color()) pixels.set(1, get_random_color()) pixels.set(2, get_random_color()) pixels.set(3, get_random_color()) #exiting the program if buttons.was_pressed(BTN_D): sys.exit() #switching to the other user if buttons.was_pressed(BTN_A): user = 1 leds.set(LED_A, True) leds.set(LED_B, False)